package mall.controller;

import mall.core.web.Controller;
import mall.entity.Product;
import mall.entity.Category;
import mall.service.ProductService;
import mall.service.CategoryService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/index")
public class IndexController extends Controller {
    private final ProductService productService = new ProductService();
    private final CategoryService categoryService = new CategoryService();

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<Product> productList = productService.list();
        List<Category> categoryList = categoryService.list();
        request.setAttribute("productList", productList);
        request.setAttribute("categoryList", categoryList);
        forward("/index", request, response);
    }
}
